﻿module poseidon.controller.property.generalpage;

public
{
	import dwt.all;
	import poseidon.globals;
	import poseidon.controller.gui;
	import poseidon.i18n.itranslatable;
	import poseidon.util.layoutshop;
	import poseidon.util.miscutil;
	import poseidon.controller.property.ipropertypage;
}

class GeneralPage : AbstractPage
{
	private Button chkShowSplash;
	private Button chkLoadWorkspace;
	//private Button chkExplorerType;

	this(Composite parent, IPropertyPage parentPage, void delegate(bool) dirtyListener)
	{
		super(parent, parentPage, dirtyListener);
		initGUI();
	}

	public void applyChanges() 
	{
		Globals.showSplash = chkShowSplash.getSelection();
		Globals.loadWorkSpaceAtStart = chkLoadWorkspace.getSelection();

		/*
		if( sGUI.packageExp )
		{
			//if( sGUI.packageExp.getProjectCount == 0 ) 
			Globals.explorerType = chkExplorerType.getSelection();
			sGUI.packageExp.refreshProject();
		}
		*/


		sGUI.packageExp.setPackageName();
		
		setDirty(false);
	}

	private Button createCheckBox(char[] langId, int initVal = false)
	{
		Button button = new Button(this, DWT.CHECK);
		with(button) {
			setData(LANG_ID, langId);
			setSelection(initVal);
			setLayoutData(LayoutDataShop.createGridData(GridData.GRAB_HORIZONTAL, 2));
			handleEvent(null, DWT.Selection, &onCheckBox);
		}
		return button;
	}

	public char[] getTitle() {
		return Globals.getTranslation("GENERAL");
	}

	private void initGUI()
	{
		setLayout(LayoutShop.createGridLayout());
		chkShowSplash = createCheckBox("gp.sw_splash", Globals.showSplash);
		chkLoadWorkspace = createCheckBox("gp.ld_wspace", Globals.loadWorkSpaceAtStart);

		/+
		with( chkExplorerType = new Button( this, DWT.CHECK ) )
		{
			setData( LANG_ID, "qp.use_sbrowser" );
			setSelection( Globals.explorerType );
			/*
			if( sGUI.packageExp )
				if( sGUI.packageExp.getProjectCount == 0 ) setEnabled( true );else setEnabled( false );
			*/
			handleEvent( null, DWT.Selection, &onCheckBox );
		}
		+/
	}

	private void onCheckBox(Event e)
	{	
		setDirty(true);
	}

	public void restoreDefaults()
	{
		chkShowSplash.setSelection( true );
		chkLoadWorkspace.setSelection( true );

		/*
		chkExplorerType.setSelection( false );
		if( sGUI.packageExp )
			if( sGUI.packageExp.getProjectCount == 0 ) chkExplorerType.setSelection( false );
		*/
		setDirty(true);
	}
}